<?php
namespace app\admin\model;
use \think\facade\View;
use \think\facade\Request;
use think\Model;

class Goods extends Model
{
    public function getIsShowAttr($v,$d)
    {
        return  $d['is_show']== 1?'是':'否';
    }
    public function getIsDownAttr($v,$d)
    {
        return  $d['is_down']==1?'是':'否';
    } public function getIsHotAttr($v,$d)
    {
        return  $d['is_hot']==1?'是':'否';
    }
    public function getAddtimeAttr($v,$d)
    {
        return date('Y-m-d', $d['addtime']);
    }

    public function searchKeywordsAttr($q,$v)
    {
        $q->where('g.name','like',"%{$v}%");
    }
    public function searchIsDownAttr($q,$v)
    {
        $q->where('g.is_down','in',$v);
    }
    public function searchIsShowAttr($q,$v)
    {
        $q->where('g.is_show','=',$v);
    }
    public function searchIsHotAttr($q,$v)
    {
        $q->where('g.is_hot','=',$v);
    }
    public function searchCidAttr($q,$v)
    {
        $q->where('g.cid','=',$v);
    }
    public function searchKtimeAttr($q,$v)
    {
        $q->where('g.addtime','>=',strtotime($v));

    }
    public function searchJtimeAttr($q,$v)
    {
        $q->where('g.addtime','<=',strtotime($v));
    }
    public function searchDPriceAttr($q,$v)
    {
        $q->where('price','<',$v);
    }
    public function searchGPriceAttr($q,$v)
    {
        $q->where('price','>',$v);
    }




    public static function getGoodlist($where)
    {
        $list=self::withSearch(array_keys($where),$where)->alias('g')
            ->join("category c",'g.cid=c.id','left')
            ->field('g.id,g.name,g.photo_x,g.price,g.addtime,g.is_show,g.is_down,g.is_hot')
            ->field('c.name cname')
            ->paginate([
                'list_rows'=>5,
                'query'=>$where
            ]);
        return $list;
    }
}